<template>
  <el-menu
    :style="{ width: isCollapse ? '60px' : '230px' }"
    default-active="2"
    class="aside-container"
    @open="handleOpen"
    @close="handleClose"
    :collapse="isCollapse"
  >
    <p class="logo-lg">{{ isCollapse ? '陪诊' : '三甲陪诊' }}</p>
    <TreeMenu :menuData="menuData" :index="1" />
  </el-menu>
</template>

<script setup>
// 用useRouter时候script一定记得写setup
import TreeMenu from './treeMenu.vue';
import { useRouter } from 'vue-router';
import { reactive, computed } from 'vue';
import { useStore } from 'vuex';

const routers = useRouter();
const menuData = reactive(routers.options.routes[0].children);
// console.log('menuData', menuData);

// 拿到store实例
const store = useStore();
// 通过计算属性拿到store里实时变化的值
const isCollapse = computed(() => {
  // 模块化时 模块名称写在后面
  return store.state.menu.isCollapse;
});
</script>

<style lang="less" scoped>
.aside-container {
  height: 100vh;
  background-color: darkslategray;
  .logo-lg {
    font-size: 20px;
    text-align: center;
    height: 50px;
    line-height: 50px;
    color: #fff;
  }
}
</style>
